package com.hxzy.member.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/*import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;*/
import com.hxzy.member.dao.MemberDao;
import com.hxzy.member.pojo.Member;
import com.hxzy.member.pojo.MemberVo;
import com.hxzy.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public Page<Member> selectByPage(Integer currPage,Integer pageSize) {
        Page<Member> memberPage = new Page<>(currPage,pageSize);
        return memberDao.selectPage(memberPage,null);
    }

    @Override
    public Map<String, Object> selectByCondition(MemberVo memberVo) {
        System.out.println(memberVo);
        Integer currentPage = memberVo.getCurrentPage();//当前页
        Integer totalPage = memberVo.getTotalPage();//每页显示数量
        if (currentPage == 1){
            memberVo.setCurrentPage(0);
        }else {
            currentPage = (currentPage - 1) * totalPage;
            memberVo.setCurrentPage(currentPage);
        }
        List<Member> members = memberDao.selectByCondition(memberVo);
        Map<String, Object> map = new HashMap<>();
        map.put("members",members);
        map.put("currentPage",memberVo.getCurrentPage());
        map.put("totalPage",memberVo.getTotalPage());
        return map;
    }


}
